<template>
    <div class="login-wrap">
        <div class="login-top">
            <div class="login-left-img">
                <img src="@/assets/img/login-left.png" alt="">
            </div>
            <div class="login-right-img">
                <img src="@/assets/img/login-right.png" alt="">
            </div>

            <div class="login-logo">
                <img src="@/assets/img/login-logo.png" alt="">
            </div>
            <div class="login-logo2">
                <img src="@/assets/img/login-logo2.png" alt="">
            </div>
        </div>

        <div class="form">
            <div class="form-title">重置密码</div>
            <div class="form-view">
                <div class="form-item">
                    <div class="form-label">手机号</div>
                    <div class="form-line"></div>
                    <div class="form-input">
                        <input type="text" v-model="form.mobile" placeholder="请输入手机号">
                    </div>
                </div>
                <div class="form-item">
                    <div class="form-label">验证码</div>
                    <div class="form-line"></div>
                    <div class="form-input">
                        <input type="text" maxlength="10" v-model="form.code" placeholder="请输入验证码">
                        <span class="form-sms" v-if="!smsSend" @click="smsSendFun">获取验证码</span>
                        <span class="form-sms" v-else>{{ smsTime }}s</span>
                    </div>
                </div>
                <div class="form-item">
                    <div class="form-label">新密码</div>
                    <div class="form-line"></div>
                    <div class="form-input">
                        <input type="password" v-model="form.password" placeholder="请输入密码">
                    </div>
                </div>
                <div class="form-btn" @click="login">确定</div>
                <div style="display: flex;justify-content: center;">
                    <div class="form-callback" @click="$router.replace('/login')">
                        <img src="@/assets/img/reset-back.png" alt="">
                        <span>返回登录</span>
                    </div>
                </div>
            </div>
            <div style="flex: 1;"></div>
            <div class="form-footer">
                <el-checkbox v-model="agree"></el-checkbox>
                <span style="margin-left: 0.125rem;">我已阅读并接受</span>
                <span>《注册声明》</span>
                <span>《版权声明》</span>
                <span>《隐私政策》</span>
            </div>
        </div>
    </div>
</template>


<script>
import {resetPassword,send} from '@/api/common'
export default {
    name: 'reset-pass',
    data() {
        return {
            smsSend: false,
            smsTime:60,
            smsTimer:null,
            form: {
                mobile: '',
                code:'',
                password: ''
            }
        }
    },
    methods: {
        smsSendFun(){
            if(this.smsSend) return;
            if(this.form.mobile == ''){
                return this.$message.error('请输入手机号');
            }
            if(!/^1[23456789]\d{9}$/.test(this.form.mobile)){
                this.$message.error('手机号格式错误')
                return
            }
            send({mobile:this.form.mobile}).then(res=>{
                if(res.code == 200){
                    this.$message.success('短信发送成功');
                    this.smsSend = true;
                    clearTimeout(this.smsTimer);
                    this.smsSend = true;
                    this.smsTimer = setInterval(()=>{
                        if(this.smsTime === 0){
                            clearTimeout(this.smsTimer);
                            this.smsSend = false;
                            this.smsTime = 60;
                            return;
                        }else{
                            this.smsTime--;
                        }
                    },1000)
                }else{
                    this.$message.error(res.msg);
                }
            })
            
        },
        login() {
            // 登录
            if(this.form.mobile == ''){
                return this.$message.error('请输入手机号');
            }
            if(!/^1[23456789]\d{9}$/.test(this.form.mobile)){
                this.$message.error('手机号格式错误')
                return
            }
            if(this.form.code == ''){
                return this.$message.error('请输入验证码');
            }
            if(this.form.password == ''){
                return this.$message.error('请输入密码');
            }
            if(this.form.password.length < 6){
                return this.$message.error('密码最少6位');
            }
            resetPassword(this.form).then(res=>{
                if(res.code == 200){
                    this.$message.success('重置密码成功');
                    this.$router.push('/login')
                }else{
                    this.$message.error(res.msg);
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
.login-wrap {
    width: 100vw;
    height: 100vh;
    background: #fff;
    /deep/.el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner{
        background-color: #4F8AF8;
        border-color: #4F8AF8;
    }
    /deep/.el-checkbox__input.is-checked+.el-checkbox__label{
        color: #4F8AF8;
    }
    /deep/.el-checkbox__label{
        font-size: 0.175rem;
        color: #999999;
    }
    .form{
        display: flex;
        flex-direction: column;
        position:absolute;
        top: 3.225rem;
        left: 8.4rem;
        width: 7.2rem;
        height: 8rem;
        background: #FFFFFF;
        box-shadow: 0px 0.025rem 0.375rem 0.0125rem rgba(79,79,79,0.3);
        border-radius: 0.2rem;
        .form-title{
            font-size: 0.3rem;
            color: #333;
            font-weight: 800;
            text-align: center;
            padding-top: 0.7rem;
        }
        .form-view{
            width: 5rem;
            margin: 0.6rem auto 0;
            .form-item{
                display: flex;
                align-items: center;
                height: 0.625rem;
                box-sizing: border-box;
                background: #FFFFFF;
                border-radius: 0.05rem;
                border: 0.0125rem solid #EEEEEE;
                margin-bottom: 0.25rem;
            }
            .form-label{
                width: 1.125rem;
                font-size: 0.175rem;
                color: #7D7D7D;
                text-align: center;

            }
            .form-line{
                width: 0.0125rem;
                    height: 0.225rem;
                    background: #EEEEEE;
            }
            .form-input{
                display: flex;
                align-items: center;
                flex: 1;
                padding-right: 0.1875rem;
                padding-left: 0.1875rem;
                height: 100%;
                box-sizing: border-box;
                .form-sms{
                    font-size: 0.175rem;
                    color: #4F8AF8;
                    cursor: pointer;
                    user-select: none;
                }
                input{
                    flex: 1;
                    font-size: 0.175rem;
                    color: #333;
                    border: none;
                    outline: none;
                    font-size: 0.175rem;
                    color: #333;
                    &::-webkit-input-placeholder{
                        font-size: 0.175rem;
                        color: #D7D7D7;
                    }
                }
            }
            .form-bottom{
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin-bottom: 0.575rem;
                span{
                    font-size: 0.175rem;
                    color: #4F8AF8;
                    cursor: pointer;
                    user-select: none;
                }
            }
            .form-btn{
                width: 5rem;
                height: 0.7rem;
                background: #4F8AF8;
                cursor: pointer;
                user-select: none;
                border-radius: 0.05rem;
                font-size: 0.225rem;
                color: #fff;
                line-height: 0.7rem;
                text-align: center;
                letter-spacing: 0.05rem;
                margin-top: 0.5rem;
            }
            .form-callback {
                display: flex;
                align-items: center;
                margin: 0.35rem auto 0;
                font-size: 0.2rem;
                color: #4F8AF8;
                border-bottom: 0.0125rem solid #4F8AF8;
                cursor: pointer;
                user-select: none;
                img{
                    width: 0.2375rem;
                    height: 0.1625rem;
                    margin-right: 0.05rem;
                }
            }
        }
        .form-footer{
            width: 100%;
            height: 0.8375rem;
            text-align: center;
            line-height: 0.8375rem;
            background: #F5F6F8;
            border-radius: 0px 0px 0.2rem 0.2rem;
            font-size: 0.2rem;
            color: #999;
            span{
                cursor: pointer;
                user-select: none;
            }
        }
    }
    .login-top{
        position: relative;
        width: 100%;
        height: 7.5rem;
        background: linear-gradient(180deg, #4F8AF8 0%, #4067F7 100%);
        .login-logo{
            position:absolute;
            top: 1.375rem ;
            left: 3.25rem;
            width: 0.9375rem;
            height: 0.6rem;
            img{
                width: 100%;
                height: 100%;
            }
        }
        .login-logo2{
            position:absolute;
            top: 1.375rem ;
            right: 3.25rem;
            width: 6.8625rem;
            height: 0.6rem;
            img{
                width: 100%;
                height: 100%;
            }
        }
        .login-left-img{
            position:absolute;
            left: 0;
            top: 0;
            width: 4.6375rem;
            height: 4.6375rem;
            img{
                width: 100%;
                height: 100%;
            }
        }
        .login-right-img{
            position:absolute;
            right: 0;
            top: 0;
            width: 7.5rem;
            height: 7.5rem;
            img{
                width: 100%;
                height: 100%;
            }
        }
    }
}
</style>